package com.yishusmt.wechatapi.wechatdev.controller;

import com.yishusmt.wechatapi.wechatdev.entity.WechatMemebrEntity;
import com.yishusmt.wechatapi.wechatdev.mapper.WechatMemebrInfoMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @author zhangyi
 * @date 2018/9/10 10:11
 */
@Controller
public class BaseController {
    @Resource
    private WechatMemebrInfoMapper wechatMemebrInfoMapper;

    @ModelAttribute
    public WechatMemebrEntity getMember(String openId){
        WechatMemebrEntity wechatMemebrEntity = wechatMemebrInfoMapper.selectMemberByOpenId(openId);
        Optional<WechatMemebrEntity> optionalMember = Optional.ofNullable(wechatMemebrEntity);
        return optionalMember.isPresent()?optionalMember.get():null;
    }
}
